using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using wildlogicgames; namespace DoomBreakers { public class PlayerEquipGenerator : MonoBehaviour { private Transform _transform; [Header("Level Generator Reference")] [Tooltip("We need to retrieve the positions available for equipment spawns.")] public LevelGenerator _levelGenerator; [Header("Prefab Broadswords to Generate")] [Tooltip("")] public GameObject[] _prefabBroadswordsObjects; [Header("Prefab Longswords to Generate")] [Tooltip("")] public GameObject[] _prefabLongswordsObjects; [Header("Prefab Mace to Generate")] [Tooltip("")] public GameObject[] _prefabMaceObjects; [Header("Prefab Shields to Generate")] [Tooltip("")] public GameObject[] _prefabShieldsObjects; [Header("Prefab Breastplates to Generate")] [Tooltip("")] public GameObject[] _prefabBreastplatesObjects; [Header("Prefab Currency to Generate")] [Tooltip("")] public GameObject[] _prefabCurrencyObjects; [Header("Prefab Barrel to Generate")] [Tooltip("")] public GameObject[] _prefabBarrelObjects; [Header("Prefab AppleTree to Generate")] [Tooltip("")] public GameObject[] _prefabAppleTreeObjects; private Dictionary _appleTreeSpawnPosDict; private Dictionary _barrelSpawnPosDict; private Dictionary _currencySpawnPosDict; private Dictionary _startEquipSpawnPosDict; private Dictionary _equipmentSpawnPosDict; private List _appleTreeSpawnPosUsedList; private List _barrelSpawnPosUsedList; private List _currencySpawnPosUsedList; private List _spawnPosUsedList; private List _startSpawnPosUsedList; //private Action[] _actionListener = new Action[1]; public void FreeMemory() { _levelGenerator = null; //for (int i = 0; i < _prefabBroadswordsObjects.Length; i++) Destroy(_prefabBroadswordsObjects[i]); //for (int i = 0; i < _prefabLongswordsObjects.Length; i++) Destroy(_prefabLongswordsObjects[i]); //for (int i = 0; i < _prefabMaceObjects.Length; i++) Destroy(_prefabMaceObjects[i]); //for (int i = 0; i < _prefabShieldsObjects.Length; i++) Destroy(_prefabShieldsObjects[i]); //for (int i = 0; i < _prefabBreastplatesObjects.Length; i++) Destroy(_prefabBreastplatesObjects[i]); //for (int i = 0; i < _prefabCurrencyObjects.Length; i++) Destroy(_prefabCurrencyObjects[i]); //for (int i = 0; i < _prefabBarrelObjects.Length; i++) Destroy(_prefabBarrelObjects[i]); //for (int i = 0; i < _prefabAppleTreeObjects.Length; i++) Destroy(_prefabAppleTreeObjects[i]); if (_appleTreeSpawnPosDict != null) _appleTreeSpawnPosDict.Clear(); if (_barrelSpawnPosDict != null) _barrelSpawnPosDict.Clear(); if (_currencySpawnPosDict != null) _currencySpawnPosDict.Clear(); if (_startEquipSpawnPosDict != null) _startEquipSpawnPosDict.Clear(); if (_equipmentSpawnPosDict != null) _equipmentSpawnPosDict.Clear(); if (_appleTreeSpawnPosUsedList != null) _appleTreeSpawnPosUsedList.Clear(); if (_barrelSpawnPosUsedList != null) _barrelSpawnPosUsedList.Clear(); if (_currencySpawnPosUsedList != null) _currencySpawnPosUsedList.Clear(); if (_spawnPosUsedList != null) _spawnPosUsedList.Clear(); if (_startSpawnPosUsedList != null) _startSpawnPosUsedList.Clear(); } private void OnDisable() { FreeMemory(); } private bool _setup = false; private void Setup() { if (LevelEventManager.GetLevelSelection() == LevelSelection.Story_ForestAct1) return; if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; if (!_levelGenerator.GenerationProcessCompleted()) return; _transform = this.transform; if (_appleTreeSpawnPosDict == null) _appleTreeSpawnPosDict = new Dictionary(); _appleTreeSpawnPosDict = _levelGenerator.GetAppleTreeSpawnDict(); if (_barrelSpawnPosDict == null) _barrelSpawnPosDict = new Dictionary(); _barrelSpawnPosDict = _levelGenerator.GetBarrelSpawnDict(); if (_currencySpawnPosDict == null) _currencySpawnPosDict = new Dictionary(); _currencySpawnPosDict = _levelGenerator.GetCurrencySpawnDict(); if (_startEquipSpawnPosDict == null) _startEquipSpawnPosDict = new Dictionary(); _startEquipSpawnPosDict = _levelGenerator.GetStartItemSpawnDict(); if (_equipmentSpawnPosDict == null) _equipmentSpawnPosDict = new Dictionary(); _equipmentSpawnPosDict = _levelGenerator.GetPlayerItemSpawnDict(); if (_spawnPosUsedList == null) _spawnPosUsedList = new List(); if (_startSpawnPosUsedList == null) _startSpawnPosUsedList = new List(); if (_currencySpawnPosUsedList == null) _currencySpawnPosUsedList = new List(); if (_barrelSpawnPosUsedList == null) _barrelSpawnPosUsedList = new List(); if (_appleTreeSpawnPosUsedList == null) _appleTreeSpawnPosUsedList = new List(); for (int i = 0; i < 6; i++) SpawnStartEquipment(i); int playerCount = 1; int playerMaxCount = 4; int randomEquipAmount = 0; int randomEquipTypeAvailable = 0; int min = playerCount; int max = (playerCount * playerMaxCount) * wildlogicgames.Utilities.GetRandomNumberInt(2, playerMaxCount + 1);//min * 2; randomEquipAmount = wildlogicgames.Utilities.GetRandomNumberInt(min, max); randomEquipTypeAvailable = 4;// 3;// wildlogicgames.Utilities.GetRandomNumberInt(0, 3);//4 types, bronze, iron,steel,ebony SpawnBroadswords(randomEquipAmount, randomEquipTypeAvailable); randomEquipAmount = wildlogicgames.Utilities.GetRandomNumberInt(min, max); randomEquipTypeAvailable = 4;//3;//wildlogicgames.Utilities.GetRandomNumberInt(0, 3);//4 types, bronze, iron,steel,ebony SpawnLongswords(randomEquipAmount, randomEquipTypeAvailable); randomEquipAmount = wildlogicgames.Utilities.GetRandomNumberInt(min, max); randomEquipTypeAvailable = 4;//3;//wildlogicgames.Utilities.GetRandomNumberInt(0, 3);//4 types, bronze, iron,steel,ebony SpawnMaces(randomEquipAmount, randomEquipTypeAvailable); randomEquipAmount = wildlogicgames.Utilities.GetRandomNumberInt(min, max); randomEquipTypeAvailable = 4;//3;//wildlogicgames.Utilities.GetRandomNumberInt(0, 3);//4 types, bronze, iron,steel,ebony SpawnShields(randomEquipAmount, randomEquipTypeAvailable); randomEquipAmount = wildlogicgames.Utilities.GetRandomNumberInt(min, max); randomEquipTypeAvailable = 4;//3;//wildlogicgames.Utilities.GetRandomNumberInt(0, 3);//4 types, bronze, iron,steel,ebony SpawnBreastplates(randomEquipAmount, randomEquipTypeAvailable); if (_currencySpawnPosDict != null) SpawnCurrency(_currencySpawnPosDict.Count - 1, 0); if (_barrelSpawnPosDict != null) SpawnBarrels(_barrelSpawnPosDict.Count); if (_appleTreeSpawnPosDict != null) SpawnAppleTree(_appleTreeSpawnPosDict.Count); //_actionListener[0] = new Action(PlayerRevived);//PlayerRevived() _setup = true; } private void SpawnAppleTree(int randomappleTreeAmount) { //_prefabCurrencyObjects GameObject obj; int j = 0; for (int i = 0; i < randomappleTreeAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _appleTreeSpawnPosDict.Count - 1); if (!_appleTreeSpawnPosUsedList.Contains(j)) _appleTreeSpawnPosUsedList.Add(j); else { for (int l = 0; l < _appleTreeSpawnPosUsedList.Count; l++) { if (j == _appleTreeSpawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _appleTreeSpawnPosDict.Count - 1); } } } obj = (GameObject)Instantiate(_prefabAppleTreeObjects[0]); obj.GetComponent()._containerLootType = ContainerLootType.Apples; obj.SetActive(true); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_appleTreeSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _appleTreeSpawnPosDict.Count - 1); if (_appleTreeSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnBarrels(int randomBarrelAmount) { //_prefabCurrencyObjects GameObject obj; int j = 0; for (int i = 0; i < randomBarrelAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _barrelSpawnPosDict.Count - 1); if (!_barrelSpawnPosUsedList.Contains(j)) _barrelSpawnPosUsedList.Add(j); else { for (int l = 0; l < _barrelSpawnPosUsedList.Count; l++) { if (j == _barrelSpawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _barrelSpawnPosDict.Count - 1); } } } obj = (GameObject)Instantiate(_prefabBarrelObjects[0]); int rand = wildlogicgames.Utilities.GetRandomNumberInt(0, 100); if (rand < 20) obj.GetComponent()._containerLootType = ContainerLootType.Nothing; if (rand > 20 && rand < 40) obj.GetComponent()._containerLootType = ContainerLootType.Apples; if (rand > 40 && rand < 60) obj.GetComponent()._containerLootType = ContainerLootType.Chicken; if (rand > 60 && rand < 80) obj.GetComponent()._containerLootType = ContainerLootType.Fish; if (rand > 80) obj.GetComponent()._containerLootType = ContainerLootType.Gold_Coins; obj.SetActive(true); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_barrelSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _barrelSpawnPosDict.Count - 1); if (_barrelSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnCurrency(int randomCurrencyAmount, int randomCurrencyType) { //_prefabCurrencyObjects GameObject obj; int j = 0; for (int i = 0; i < randomCurrencyAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _currencySpawnPosDict.Count - 1); if (!_currencySpawnPosUsedList.Contains(j)) _currencySpawnPosUsedList.Add(j); else { for (int l = 0; l < _currencySpawnPosUsedList.Count; l++) { if (j == _currencySpawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _currencySpawnPosDict.Count - 1); } } } int k = 0;// wildlogicgames.Utilities.GetRandomNumberInt(0, randomCurrencyType); int rand = wildlogicgames.Utilities.GetRandomNumberInt(0, 111); if (rand < 66) k = 0; if (rand > 66 && rand < 77) k = 1; if (rand > 77 && rand < 88) k = 2; if (rand > 88 && rand < 99) k = 3; if (rand > 99 && rand < 111) k = 4; obj = (GameObject)Instantiate(_prefabCurrencyObjects[k]); //Relates to corrisponding order set in prefab references. if (k == 0) obj.GetComponent()._itemID = i; if (k == 1) obj.GetComponent()._itemID = i; if (k == 2) obj.GetComponent()._itemID = i; if (k == 3) obj.GetComponent()._itemID = i; if (k == 4) obj.GetComponent()._itemID = i; obj.SetActive(true); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_currencySpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _currencySpawnPosDict.Count - 1); if (_currencySpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnStartEquipment(int i) { //if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; GameObject obj; obj = (GameObject)Instantiate(_prefabBroadswordsObjects[0]); obj.GetComponent()._itemID = i; obj.GetComponent()._swordID = PlayerItem.IsBroadsword; obj.GetComponent()._weaponType = EquipmentWeaponType.Broadsword; obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; obj.SetActive(true); Vector3 spawnPos;// = _levelGenerator.GetStartItemSpawnDict(); if (_startEquipSpawnPosDict.TryGetValue(i, out spawnPos)) obj.transform.position = spawnPos; obj.transform.parent = _transform; } private void SpawnBroadswords(int randomBroadswordAmount, int randomBroadswordTypeAvailable) { if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; GameObject obj; int j = 0; for (int i = 0; i < randomBroadswordAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (!_spawnPosUsedList.Contains(j)) _spawnPosUsedList.Add(j); else { for (int l = 0; l < _spawnPosUsedList.Count; l++) { if (j == _spawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); } } } int k = wildlogicgames.Utilities.GetRandomNumberInt(0, randomBroadswordTypeAvailable); obj = (GameObject)Instantiate(_prefabBroadswordsObjects[k]); obj.GetComponent()._itemID = i; obj.GetComponent()._swordID = PlayerItem.IsBroadsword; obj.GetComponent()._weaponType = EquipmentWeaponType.Broadsword; randomBroadswordTypeAvailable = k; if (randomBroadswordTypeAvailable == 0) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (randomBroadswordTypeAvailable == 1) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (randomBroadswordTypeAvailable == 2) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (randomBroadswordTypeAvailable == 3) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; if (randomBroadswordTypeAvailable == 4) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; obj.SetActive(true); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnLongswords(int randomLongswordAmount, int randomLongswordTypeAvailable) { if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; GameObject obj; int j = 0; for (int i = 0; i < randomLongswordAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (!_spawnPosUsedList.Contains(j)) _spawnPosUsedList.Add(j); else { for (int l = 0; l < _spawnPosUsedList.Count; l++) { if (j == _spawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); } } } int k = wildlogicgames.Utilities.GetRandomNumberInt(0, randomLongswordTypeAvailable); obj = (GameObject)Instantiate(_prefabLongswordsObjects[k]);//_prefabBroadswordsObjects[k]; obj.GetComponent()._itemID = i; obj.GetComponent()._swordID = PlayerItem.IsLongsword; obj.GetComponent()._weaponType = EquipmentWeaponType.Longsword; randomLongswordTypeAvailable = k; if (randomLongswordTypeAvailable == 0) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (randomLongswordTypeAvailable == 1) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (randomLongswordTypeAvailable == 2) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (randomLongswordTypeAvailable == 3) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; if (randomLongswordTypeAvailable == 4) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; obj.SetActive(true); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnMaces(int randomMaceAmount, int randomMaceTypeAvailable) { if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; GameObject obj; int j = 0; for (int i = 0; i < randomMaceAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (!_spawnPosUsedList.Contains(j)) _spawnPosUsedList.Add(j); else { for (int l = 0; l < _spawnPosUsedList.Count; l++) { if (j == _spawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); } } } int k = wildlogicgames.Utilities.GetRandomNumberInt(0, randomMaceTypeAvailable); obj = (GameObject)Instantiate(_prefabMaceObjects[k]);//_prefabBroadswordsObjects[k]; obj.GetComponent()._itemID = i; obj.GetComponent()._maceID = PlayerItem.IsMace; obj.GetComponent()._weaponType = EquipmentWeaponType.MorningstarMace; randomMaceTypeAvailable = k; if (randomMaceTypeAvailable == 0) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (randomMaceTypeAvailable == 1) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (randomMaceTypeAvailable == 2) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (randomMaceTypeAvailable == 3) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; if (randomMaceTypeAvailable == 4) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; obj.SetActive(true); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnShields(int randomShieldAmount, int randomShieldTypeAvailable) { if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; GameObject obj; int j = 0; for (int i = 0; i < randomShieldAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (!_spawnPosUsedList.Contains(j)) _spawnPosUsedList.Add(j); else { for (int l = 0; l < _spawnPosUsedList.Count; l++) { if (j == _spawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); } } } int k = wildlogicgames.Utilities.GetRandomNumberInt(0, randomShieldTypeAvailable); obj = (GameObject)Instantiate(_prefabShieldsObjects[k]);//_prefabBroadswordsObjects[k]; obj.SetActive(true); obj.GetComponent()._itemID = i; PlayerItem shieldID = PlayerItem.IsShield; obj.GetComponent()._shieldType = EquipmentArmorType.Shield; EquipmentMaterialType materialType = EquipmentMaterialType.Bronze; randomShieldTypeAvailable = k; if (randomShieldTypeAvailable == 0) materialType = EquipmentMaterialType.Bronze; if (randomShieldTypeAvailable == 1) materialType = EquipmentMaterialType.Iron; if (randomShieldTypeAvailable == 2) materialType = EquipmentMaterialType.Steel; if (randomShieldTypeAvailable == 3) materialType = EquipmentMaterialType.Ebony; if (randomShieldTypeAvailable == 4) materialType = EquipmentMaterialType.Ebony; obj.GetComponent().Initialize(obj.GetComponent(), obj.GetComponent(), PlayerAnimatorController.Weapon_equipment_to_pickup, ItemAnimationState.IdleShield, shieldID, materialType); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } private void SpawnBreastplates(int randomBreastplateAmount, int randomBreastplateTypeAvailable) { if (LevelEventManager.GetLevelSelection() == LevelSelection.Level_ForestCampsite) return; GameObject obj; int j = 0; for (int i = 0; i < randomBreastplateAmount; i++) { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (!_spawnPosUsedList.Contains(j)) _spawnPosUsedList.Add(j); else { for (int l = 0; l < _spawnPosUsedList.Count; l++) { if (j == _spawnPosUsedList[l]) { l = 0; j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); } } } int k = wildlogicgames.Utilities.GetRandomNumberInt(0, randomBreastplateTypeAvailable); obj = (GameObject)Instantiate(_prefabBreastplatesObjects[k]);//_prefabBroadswordsObjects[k]; obj.SetActive(true); obj.GetComponent()._itemID = i; PlayerItem armorID = PlayerItem.IsBreastPlate; obj.GetComponent()._armorType = EquipmentArmorType.Breastplate; EquipmentMaterialType materialType = EquipmentMaterialType.Bronze; randomBreastplateTypeAvailable = k; if (randomBreastplateTypeAvailable == 0) materialType = EquipmentMaterialType.Bronze; if (randomBreastplateTypeAvailable == 1) materialType = EquipmentMaterialType.Iron; if (randomBreastplateTypeAvailable == 2) materialType = EquipmentMaterialType.Steel; if (randomBreastplateTypeAvailable == 3) materialType = EquipmentMaterialType.Ebony; if (randomBreastplateTypeAvailable == 4) materialType = EquipmentMaterialType.Ebony; obj.GetComponent().Initialize(obj.GetComponent(), obj.GetComponent(), PlayerAnimatorController.Weapon_equipment_to_pickup, ItemAnimationState.IdleBreastplate, armorID, materialType); //obj.transform.position = _equipmentSpawnPosDict[j]; Vector3 spawnPos; if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; else { j = wildlogicgames.Utilities.GetRandomNumberInt(0, _equipmentSpawnPosDict.Count - 1); if (_equipmentSpawnPosDict.TryGetValue(j, out spawnPos)) obj.transform.position = spawnPos; } obj.transform.parent = _transform; } } //private void OnEnable() => UIPlayerManager.Subscribe("ReportUIPlayerStatsRevived", _actionListener[0]); //private void OnDisable() => UIPlayerManager.Unsubscribe("ReportUIPlayerStatsRevived", _actionListener[0]); private void PlayerRevived() { //We can use this event to identify when player is reviving from death. //Now we have a working start point to spawn in a low class weapon for the //player to use. We will use the Start Point & Campsite Point for this. int campsiteCount = LevelEventManager.GetActivatedCampsiteCount(); for (int i = 0; i < campsiteCount; i++) { RespawnWeapon(i); RespawnArmor(i); } int playerId = 0; LevelEventManager.UpdateRespawnEquip(playerId, false); } private void RespawnWeapon(int i) { GameObject obj; obj = (GameObject)Instantiate(_prefabBroadswordsObjects[0]); obj.GetComponent()._itemID = i; obj.GetComponent()._swordID = PlayerItem.IsBroadsword; obj.GetComponent()._weaponType = EquipmentWeaponType.Broadsword; obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; obj.SetActive(true); Vector3 spawnPos;// = _levelGenerator.GetStartItemSpawnDict(); if (_startEquipSpawnPosDict.TryGetValue(i, out spawnPos)) //i = 0, 1 is start pos and checkpoint pos (campsite) { int randX = wildlogicgames.Utilities.GetRandomNumberInt(0, 3); spawnPos.x += randX; obj.transform.position = spawnPos; } obj.transform.parent = _transform; } private void RespawnArmor(int i) { GameObject obj; obj = (GameObject)Instantiate(_prefabBreastplatesObjects[0]); obj.GetComponent()._itemID = i; PlayerItem armorID = PlayerItem.IsBreastPlate; obj.GetComponent()._armorType = EquipmentArmorType.Breastplate; EquipmentMaterialType materialType = EquipmentMaterialType.Bronze; obj.GetComponent().Initialize(obj.GetComponent(), obj.GetComponent(), PlayerAnimatorController.Weapon_equipment_to_pickup, ItemAnimationState.IdleBreastplate, armorID, materialType); obj.SetActive(true); Vector3 spawnPos;// = _levelGenerator.GetStartItemSpawnDict(); if (_startEquipSpawnPosDict.TryGetValue(i, out spawnPos)) //i = 0, 1 is start pos and checkpoint pos (campsite) { int randX = wildlogicgames.Utilities.GetRandomNumberInt(0, 3); spawnPos.x += randX; obj.transform.position = spawnPos; } obj.transform.parent = _transform; } public void SpawnTheBroadsword(EquipmentMaterialType equipmentMaterialType, int id, Vector3 spawnPos) { int i = 0; if (equipmentMaterialType == EquipmentMaterialType.Bronze) i = 0; if (equipmentMaterialType == EquipmentMaterialType.Iron) i = 1; if (equipmentMaterialType == EquipmentMaterialType.Steel) i = 2; if (equipmentMaterialType == EquipmentMaterialType.Ebony) i = 3; GameObject obj = (GameObject)Instantiate(_prefabBroadswordsObjects[i]); obj.GetComponent()._itemID = id; obj.GetComponent()._swordID = PlayerItem.IsBroadsword; obj.GetComponent()._weaponType = EquipmentWeaponType.Broadsword; if (equipmentMaterialType == EquipmentMaterialType.Bronze) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (equipmentMaterialType == EquipmentMaterialType.Iron) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (equipmentMaterialType == EquipmentMaterialType.Steel) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (equipmentMaterialType == EquipmentMaterialType.Ebony) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; obj.SetActive(true); obj.transform.position = spawnPos; obj.transform.parent = _transform; } public void SpawnTheLongsword(EquipmentMaterialType equipmentMaterialType, int id, Vector3 spawnPos) { int i = 0; if (equipmentMaterialType == EquipmentMaterialType.Bronze) i = 0; if (equipmentMaterialType == EquipmentMaterialType.Iron) i = 1; if (equipmentMaterialType == EquipmentMaterialType.Steel) i = 2; if (equipmentMaterialType == EquipmentMaterialType.Ebony) i = 3; GameObject obj = (GameObject)Instantiate(_prefabLongswordsObjects[i]); obj.GetComponent()._itemID = id; obj.GetComponent()._swordID = PlayerItem.IsLongsword; obj.GetComponent()._weaponType = EquipmentWeaponType.Longsword; if (equipmentMaterialType == EquipmentMaterialType.Bronze) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (equipmentMaterialType == EquipmentMaterialType.Iron) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (equipmentMaterialType == EquipmentMaterialType.Steel) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (equipmentMaterialType == EquipmentMaterialType.Ebony) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; obj.SetActive(true); obj.transform.position = spawnPos; obj.transform.parent = _transform; } public void SpawnTheMorningstarMace(EquipmentMaterialType equipmentMaterialType, int id, Vector3 spawnPos) { int i = 0; if (equipmentMaterialType == EquipmentMaterialType.Bronze) i = 0; if (equipmentMaterialType == EquipmentMaterialType.Iron) i = 1; if (equipmentMaterialType == EquipmentMaterialType.Steel) i = 2; if (equipmentMaterialType == EquipmentMaterialType.Ebony) i = 3; GameObject obj = (GameObject)Instantiate(_prefabMaceObjects[i]); obj.GetComponent()._itemID = id; obj.GetComponent()._maceID = PlayerItem.IsMace; obj.GetComponent()._weaponType = EquipmentWeaponType.MorningstarMace; if (equipmentMaterialType == EquipmentMaterialType.Bronze) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (equipmentMaterialType == EquipmentMaterialType.Iron) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (equipmentMaterialType == EquipmentMaterialType.Steel) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (equipmentMaterialType == EquipmentMaterialType.Ebony) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; obj.SetActive(true); obj.transform.position = spawnPos; obj.transform.parent = _transform; } public void SpawnTheShield(EquipmentMaterialType equipmentMaterialType, int id, Vector3 spawnPos) { int i = 0; if (equipmentMaterialType == EquipmentMaterialType.Bronze) i = 0; if (equipmentMaterialType == EquipmentMaterialType.Iron) i = 1; if (equipmentMaterialType == EquipmentMaterialType.Steel) i = 2; if (equipmentMaterialType == EquipmentMaterialType.Ebony) i = 3; GameObject obj = (GameObject)Instantiate(_prefabShieldsObjects[i]); obj.GetComponent()._itemID = id; obj.GetComponent()._shieldID = PlayerItem.IsShield; obj.GetComponent()._shieldType = EquipmentArmorType.Shield; if (equipmentMaterialType == EquipmentMaterialType.Bronze) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (equipmentMaterialType == EquipmentMaterialType.Iron) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (equipmentMaterialType == EquipmentMaterialType.Steel) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (equipmentMaterialType == EquipmentMaterialType.Ebony) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; obj.SetActive(true); obj.transform.position = spawnPos; obj.transform.parent = _transform; } public void SpawnTheBreastplate(EquipmentMaterialType equipmentMaterialType, int id, Vector3 spawnPos) { int i = 0; if (equipmentMaterialType == EquipmentMaterialType.Bronze) i = 0; if (equipmentMaterialType == EquipmentMaterialType.Iron) i = 1; if (equipmentMaterialType == EquipmentMaterialType.Steel) i = 2; if (equipmentMaterialType == EquipmentMaterialType.Ebony) i = 3; GameObject obj = (GameObject)Instantiate(_prefabBreastplatesObjects[i]); obj.GetComponent()._itemID = id; obj.GetComponent()._armorID = PlayerItem.IsBreastPlate; obj.GetComponent()._armorType = EquipmentArmorType.Breastplate; if (equipmentMaterialType == EquipmentMaterialType.Bronze) obj.GetComponent()._materialType = EquipmentMaterialType.Bronze; if (equipmentMaterialType == EquipmentMaterialType.Iron) obj.GetComponent()._materialType = EquipmentMaterialType.Iron; if (equipmentMaterialType == EquipmentMaterialType.Steel) obj.GetComponent()._materialType = EquipmentMaterialType.Steel; if (equipmentMaterialType == EquipmentMaterialType.Ebony) obj.GetComponent()._materialType = EquipmentMaterialType.Ebony; obj.SetActive(true); obj.transform.position = spawnPos; obj.transform.parent = _transform; } //private void Awake() => Setup(); void Start() { } void Update() { if (!_setup) Setup(); //LevelGenerator.cs must Awake() before this. int playerId = 0; if (LevelEventManager.RespawnEquipFlag(playerId)) PlayerRevived(); } } }